//
//  StatusListViewModel.swift
//  Weibo
//
//  Created by 付启刚 on 15/12/23.
//  Copyright © 2015年 faq. All rights reserved.
//

import UIKit
import SVProgressHUD
class StatusListViewModel: NSObject {
    class func loadHomePageData(since_id: Int64,max_id: Int64,finished:(statuses:[Status]?)->()){
        let urlString="2/statuses/home_timeline.json"
        //判断token是否为空
        guard let token = UserAccountViewModel().token else{
            print("token为空")
            SVProgressHUD.showInfoWithStatus("请重新登录")
            return
        }
        var parameters=["access_token":token]
        if since_id>0 {
          parameters["since_id"]="\(since_id)"
        
        }
        if max_id>0{
        parameters["max_id"]="\(max_id-1)"
        }
        NetWorkTools.sharedTools.requestJSONDict(.GET, urlString: urlString, parameters: parameters) { (dict, error) -> () in
            if error != nil {
                SVProgressHUD.showInfoWithStatus("您的网络出错,请稍后再试")
                finished(statuses: nil)
                return
            }
            //请求成功
            if let array=dict!["statuses"] as? [[String:AnyObject]]{
                //print(array)
                var list=[Status]()
                for item in array{
                    //print(item["text"])
                    let s=Status(dict:item)
                    list .append(s)
                }
                finished(statuses: list)
//                self.statuses=list
//                //刷新表视图
//                self.tableView .reloadData()
            }
            
        }

    }
}
